package com.lzb.newloan.netData;

import android.content.Context;
import android.widget.Toast;

import com.lzb.newloan.pojo.MoneyPojo;
import com.lzb.newloan.pojo.PersonPojo;
import com.lzb.newloan.utils.TimeUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/8/16.
 */

public class netArrayData {

    public ArrayList<PersonPojo> homearrayData(JSONArray jsonArray, Context context){
        ArrayList<PersonPojo> arrPojos = new ArrayList<PersonPojo>();
//					record_list.isStart = false;
        try {
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject json = jsonArray.getJSONObject(i);
            PersonPojo pojo = new PersonPojo();
            String time[] = json.getString("create_date")//2017-04-21 14:31:10
                    .split(" ");
            String time1[] = time[0].split("-");
            String time2[] = time[1].split(":");
            pojo.setCreate_date(time1[1] + "/" + time1[2]+" "+time2[0] + ":" + time2[1]);

            pojo.setCardusername(json.getString("cardusername")
                    .substring(0, 1) + "**");
            pojo.setJk_money(json.getInt("jk_money"));
            arrPojos.add(pojo);
        }
        } catch (JSONException e) {
            Toast.makeText(context, "数据解析错误", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
        return arrPojos;
    }


    public ArrayList<MoneyPojo> newsarrayData(JSONArray jsonArray, Context context){
        ArrayList<MoneyPojo> arrayList2 = new ArrayList<MoneyPojo>();
        try {
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject object = (JSONObject) jsonArray.get(i);
            MoneyPojo pojo = new MoneyPojo();
            JSONObject time = object.getJSONObject("fb_time");
            pojo.setTime(TimeUtils.parseDate(Long
                    .parseLong(time.getString("time"))));
            pojo.setName(object.getString("title"));
            pojo.setType(object.getString("neirong"));
            arrayList2.add(pojo);
        }
    } catch (JSONException e) {
        Toast.makeText(context, "数据解析错误", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
        return arrayList2;
    }

}
